public class Account {

//	编写一个帐户类实现银行帐户的概念，创建帐户类的对象，完成存款与取款等操作。

	// 账户属性：账号、姓名、余额
	private String accountId;   // 账号
	private String name;        // 账户姓名
	private double balance;     // 账户余额

	// 构造方法：初始化账号和姓名，余额默认为0
	public Account(String accountId, String name) {
		this.accountId = accountId;
		this.name = name;
		this.balance = 0.0;
	}

	// 构造方法：初始化所有属性
	public Account(String accountId, String name, double initialBalance) {
		this.accountId = accountId;
		this.name = name;
		// 初始余额不能为负数
		if (initialBalance >= 0) {
			this.balance = initialBalance;
		} else {
			this.balance = 0.0;
			System.out.println("初始余额不能为负数，已默认设置为0");
		}
	}

	// 存款操作
	public void deposit(double amount) {
		if (amount > 0) {
			balance += amount;
			System.out.println("存款成功！存入金额：" + amount + "，当前余额：" + balance);
		} else {
			System.out.println("存款金额必须为正数！");
		}
	}

	// 取款操作
	public void withdraw(double amount) {
		if (amount <= 0) {
			System.out.println("取款金额必须为正数！");
			return;
		}
		if (amount > balance) {
			System.out.println("余额不足！当前余额：" + balance + "，取款失败");
		} else {
			balance -= amount;
			System.out.println("取款成功！取出金额：" + amount + "，当前余额：" + balance);
		}
	}

	// 查询账户信息
	public void queryInfo() {
		System.out.println("=====账户信息=====");
		System.out.println("账号：" + accountId);
		System.out.println("姓名：" + name);
		System.out.println("当前余额：" + balance);
		System.out.println("==================");
	}

	public static void main(String[] args) {
		// 创建账户1：使用默认初始余额（0）
		Account account1 = new Account("6228481234567890123", "张三");
		account1.queryInfo();
		account1.deposit(1000);   // 存款1000
		account1.withdraw(300);   // 取款300
		account1.queryInfo();

		// 创建账户2：设置初始余额
		Account account2 = new Account("6228489876543210123", "李四", 500);
		account2.queryInfo();
		account2.withdraw(600);   // 尝试取款超过余额
		account2.deposit(2000);   // 存款2000
		account2.withdraw(1500);  // 取款1500
		account2.queryInfo();
	}
}
